package com.sxfq.loansupermarket.backsystem.modular.logsf.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.modular.logsf.entity.DistributiveDoctorLogInfo;
import com.sxfq.loansupermarket.backsystem.modular.logsf.entity.SearchDistributiveDoctorLogInfo;
import com.sxfq.loansupermarket.backsystem.modular.logsf.service.IDistributiveDoctorLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 *
 * @author py
 * @Date 2018年4月19日23:15:54
 */
@Controller
@RequestMapping("/distributiveDoctorLog")
public class DistributiveDoctorLogController extends BaseController {
    @Autowired
    IDistributiveDoctorLogService service;
 
    private String PREFIX = "/logsf/distributiveDoctorLog/";

    @RequestMapping(value = "")
    public String refund(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return PREFIX + "distributive_doctor_log.html";
    }

    /**
     *
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object list(SearchDistributiveDoctorLogInfo info, HttpServletRequest request) {
        Page<DistributiveDoctorLogInfo> page = new PageFactory<DistributiveDoctorLogInfo>().defaultPage();
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<DistributiveDoctorLogInfo> list = service.getList(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = service.getList(page, info);
            }
            page.setRecords(list);
            page.setTotal(service.getQueryPagesCount(page, info));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }
}